
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="d" uri="/WEB-INF/resource.tld" %>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>

</head>

<body>

<%@ include file="/WEB-INF/include/header.jsp"%>

<%@ include file="/WEB-INF/include/menu.jsp"%>

<div class="container main-content">

  <div class="panel panel-default x-panel x-panel-layout">

    <div class="panel-heading">
      <ol class="breadcrumb">
        <li><a href="${ctx.host}/system">电商管理</a></li>
        <li class="active">课程管理</li>
      </ol>
    </div>

    <div class="panel-body schedule-panel-body">

      <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
        <%@ include file="/WEB-INF/include/submenu.jsp"%>
      </div>

      <div class="col-xs-10 x-panel-layout-right">

        <div class="x-breadcrumb-wrapper">
          <div class="x-breadcrumb clearfix">
            <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>课程管理&nbsp;-&nbsp;排期表</span></h2>
            <div class="pull-right">
              <c:choose>
                <c:when test="${not empty currentPrincipal.site}">
                  <span class="current-branchCode">${currentPrincipal.site.name}</span>
                </c:when>
                <c:otherwise>
                  <select name="site">
                    <option value="">所有门店</option>
                    <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                      <option value="${site.id}" ${site.id == param.site ? 'selected' : ''}>${site.name}</option>
                    </c:forEach>
                  </select>
                </c:otherwise>
              </c:choose>
            </div>
          </div>
        </div>

        <div class="form-horizontal clearfix" style="${currentPrincipal.admin or currentPrincipal.areaManager or currentPrincipal.siteManager or currentPrincipal.areaServer or currentPrincipal.siteServer ? 'height:50px;' : currentPrincipal.root ? 'height:70px;' : ''}">

          <div class="btn-group pull-right" role="group" aria-label="..." style="margin-left: 30px;">
            <a href="${ctx.host}/schedules?site=${site.id}" class="btn btn-success">教练</a>
            <a href="${ctx.host}/schedules?coachview=false&site=${site.id}" class="btn btn-default">日期</a>
          </div>

          <div class="btn-group pull-right" style="${currentPrincipal.root ? 'width:420px;' : ''}">
            <a href="${ctx.host}/schedules/search${not empty queryString ? '?' : ''}${queryString}" data-target="#" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default init-button hide">
              <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
            </a>
            <c:if test="${currentPrincipal.areaManager or currentPrincipal.siteManager or currentPrincipal.root}">
              <a href="${ctx.host}/schedules/batch-schedule?site=${site.id}" data-target="#batch-schedule" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default init-button hide">批量排班</a>
            </c:if>
            <c:if test="${currentPrincipal.schedule}">
              <a href="${ctx.host}/schedules/annual-leave" data-target="#annual-leave" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default init-button hide">排年假</a>
            </c:if>
            <c:if test="${currentPrincipal.schedule or currentPrincipal.areaServer or currentPrincipal.siteServer}">
              <a href="${ctx.host}/schedules/export-view?view=coach" data-target="#export-schedule" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default init-button hide">导出课程表</a>
            </c:if>
            <c:if test="${currentPrincipal.admin or currentPrincipal.root or currentPrincipal.marketingManager}">
              <a href="${ctx.host}/schedules/batch-business-calendar" data-target="#batch-business-calendar" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default init-button hide">批量公出</a>
            </c:if>
          </div>

          <div class="color-annotation pull-left" style="width:490px;">
            <span><label class="individual"></label>1v1</span>
            <span><label class="year"></label>周期</span>
            <span><label class="special"></label>特色</span>
            <span><label class="annual-leave"></label>特色75min</span>
            <span><label class="posture"></label>专项</span>
            <span><label class="give"></label>赠课</span>
            <span><label class="rest"></label>休息</span>
            <span><label class="experience"></label>体验课</span>
            <span><label class="duty"></label>值班</span>
            <span><label class="business"></label>公出</span>
            <span><label class="conference"></label>会议</span>
            <span><label class="training"></label>培训</span>
          </div>

        </div>

        <c:set var="start" value="${persist.startEndHour(site)['start']}"/>
        <c:set var="end" value="${persist.startEndHour(site)['end']}"/>
        <div style="overflow: hidden; width: 100%;">
          <table class="table table-bordered schedule-table text-center scheduler-table" style="margin-top: 20px; margin-bottom: 0; width:100% !important; font-size: 12px;table-layout: fixed;">
            <colgroup>
              <col style="width: 80px">
              <col style="width:76px">
              <c:forEach var="hh"  begin="${start}" end="${end}">
                <col>
                <col>
              </c:forEach>
              <col style="width:187px">
            </colgroup>
            <!-- schedule header -->
            <%@ include file="/WEB-INF/jsps/course/schedule/pattern/table-header.jsp"%>
            <!-- end schedule header -->
            <tbody>
            <tr>
              <td>教练</td>
              <td>日期</td>
              <c:forEach var="hh"  begin="${start}" end="${end}">
                <td colspan="2">${hh<10 ? '0' : ''}${hh}:00</td>
              </c:forEach>
              <td></td>
            </tr>
            </tbody>
          </table>
        </div>
        <div style="width: 100%; overflow: scroll;" class="table-scroll-wrap schedule-table-scroll-wrap">
          <table class="table table-bordered schedule-table text-center scheduler-table" style="margin-top: 0px; width:100% !important; font-size: 12px;table-layout: fixed;">
            <colgroup>
              <col style="width:80px">
              <col style="width:76px">
              <c:forEach var="hh"  begin="${start}" end="${end}">
                <col>
                <col>
              </c:forEach>
              <col style="width:170px">
            </colgroup>
            <tbody>
            <c:set var="coachRelations" value="${persist.coachRelations}"/>
            <c:forEach var="principal" items="${persist.coaches(currentPrincipal.id, site.id)}">
              <c:if test="${principal.value.coach}">
                <c:choose>
                  <c:when test="${not empty param.coachId}">
                    <c:if test="${principal.key eq param.coachId}">
                      <c:forEach var="date" items="${dates}" varStatus="status">
                        <tr>
                          <c:if test="${status.index eq 0}">
                            <td rowspan="7" style="text-align: center; vertical-align: middle; background-color: #E8E8E8;">
                                ${principal.value.name}</td>
                          </c:if>
                          <td style="vertical-align: inherit;"><fmt:formatDate value="${date}" pattern="M月dd日" /></td>
                          <fmt:formatDate value="${date}" pattern="yyyyMMdd" var="occurDate"></fmt:formatDate>
                          <fmt:formatDate value="${date}" pattern="yyyyMMdd" var="day" />
                          <c:forEach var="hour" begin="${start}" end="${end}">
                          
                            <c:set var="beforeHourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}00" />
                            <c:set var="beforeHalfhourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}30" />
                            <c:set var="hourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}00" />
                            <c:set var="halfhourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}30"/>
                            
                            <!-- 9:30没课 && （9:00没课 || 9:00有非体验课） -->
                            <c:if test="${empty courseSchedules[beforeHalfhourKey] and (empty courseSchedules[beforeHourKey] || (not empty courseSchedules[beforeHourKey] && courseSchedules[beforeHourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                              <td data-hour="${hourKey}"
                                  class="ellipsis  ${persist.getScheduleAlias(courseSchedules[hourKey][0], restSchedules[hourKey])}"
                                  colspan="${not empty courseSchedules[hourKey] ? courseSchedules[hourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                                <c:choose>
                                  <c:when test="${not empty courseSchedules[hourKey]}">
                                    <a class="${courseSchedules[hourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[hourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[hourKey][0].courseRound.id}" style="color:#fff">
                                        ${courseSchedules[hourKey][0].student.name}
                                    </a>
                                  </c:when>
                                  <c:when test="${empty courseSchedules[hourKey] and empty restSchedules[hourKey]}">

                                  </c:when>
                                  <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and empty persist.containDuty(restSchedules[hourKey])}">
                                    值班
                                  </c:when>
                                  <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and not empty persist.containDuty(restSchedules[hourKey])}">
                                    ${persist.containDuty(restSchedules[hourKey]).coachRestType.description}
                                  </c:when>
                                </c:choose>
                              </td>
                            </c:if>
                            <c:if test="${empty courseSchedules[hourKey] and (empty courseSchedules[beforeHalfhourKey] || (not empty courseSchedules[beforeHalfhourKey] && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                              <td data-hour="${halfhourKey}"
                                  class="ellipsis ${persist.getScheduleAlias(courseSchedules[halfhourKey][0], restSchedules[halfhourKey])}"
                                  colspan="${not empty courseSchedules[halfhourKey] ? courseSchedules[halfhourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                                <c:choose>
                                  <c:when test="${not empty courseSchedules[halfhourKey]}">
                                    <a class="${courseSchedules[halfhourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[halfhourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[halfhourKey][0].courseRound.id}" style="color:#fff">
                                        ${courseSchedules[halfhourKey][0].student.name}
                                    </a>
                                  </c:when>
                                  <c:when test="${empty courseSchedules[halfhourKey] and empty restSchedules[halfhourKey]}">

                                  </c:when>
                                  <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and empty persist.containDuty(restSchedules[halfhourKey])}">
                                    值班
                                  </c:when>
                                  <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and not empty persist.containDuty(restSchedules[halfhourKey])}">
                                    ${persist.containDuty(restSchedules[halfhourKey]).coachRestType.description}
                                  </c:when>
                                </c:choose>
                              </td>
                            </c:if>
                          </c:forEach>

                          <td>
                            <c:if test="${date >= today && (currentPrincipal.schedule || currentPrincipal.areaServer || currentPrincipal.siteServer)}">
                              <a href="${ctx.host}/schedules/calendar-edit?coach=${principal.key}&date=${day}&site=${coachRelations[principal.key].id}" data-toggle="modal" data-target="#schedule-edit">更改课时</a>
                              <a href="${ctx.host}/schedules/add-experience?coach=${principal.key}&date=${day}&site=${coachRelations[principal.key].id}" class="init-button hide" data-toggle="modal" data-target="#experience-add">体验</a>
                              <a href="${ctx.host}/schedules/cancel-experience?coach=${principal.key}&date=${day}&site=${coachRelations[principal.key].id}" class="init-button hide" data-toggle="modal" data-target="#experience-cancel">取消体验</a>
                            </c:if>
                          </td>
                        </tr>
                      </c:forEach>
                    </c:if>
                  </c:when>
                  <c:otherwise>
                    <c:forEach var="date" items="${dates}" varStatus="status">
                      <tr>
                        <c:if test="${status.index eq 0}">
                          <td rowspan="7" style="text-align: center; vertical-align: middle; background-color: #E8E8E8;">${principal.value.name}</td>
                        </c:if>
                        <td style="vertical-align: inherit;"><fmt:formatDate value="${date}" pattern="M月dd日"/></td>
                        <fmt:formatDate value="${date}" pattern="yyyyMMdd" var="occurDate"></fmt:formatDate>
                        <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day"></fmt:formatDate>

                        <c:forEach var="hour" begin="${start}" end="${end}">
                          <c:set var="beforeHourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}00" />
                          <c:set var="beforeHalfhourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}30" />
                          <c:set var="hourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}00" />
                          <c:set var="halfhourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}30"/>
                          <c:if test="${empty courseSchedules[beforeHalfhourKey] and (empty courseSchedules[beforeHourKey] || (not empty courseSchedules[beforeHourKey] && courseSchedules[beforeHourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                            <td data-hour="${hourKey}"
                                class="ellipsis ${persist.getScheduleAlias(courseSchedules[hourKey][0], restSchedules[hourKey])}"
                                colspan="${not empty courseSchedules[hourKey] ? courseSchedules[hourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                              <c:choose>
                                <c:when test="${not empty courseSchedules[hourKey]}">
                                  <a class="${courseSchedules[hourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[hourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[hourKey][0].courseRound.id}" style="color:#fff">
                                      ${courseSchedules[hourKey][0].student.name}
                                  </a>
                                </c:when>
                                <c:when test="${empty courseSchedules[hourKey] and empty restSchedules[hourKey]}">

                                </c:when>
                                <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and empty persist.containDuty(restSchedules[hourKey])}">
                                  值班
                                </c:when>
                                <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and not empty persist.containDuty(restSchedules[hourKey])}">
                                  ${persist.containDuty(restSchedules[hourKey]).coachRestType.description}
                                </c:when>
                              </c:choose>
                            </td>
                          </c:if>
                          <c:if test="${empty courseSchedules[hourKey] and (empty courseSchedules[beforeHalfhourKey] || (not empty courseSchedules[beforeHalfhourKey] && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                            <td data-hour="${halfhourKey}"
                                class="ellipsis ${persist.getScheduleAlias(courseSchedules[halfhourKey][0], restSchedules[halfhourKey])}"
                                colspan="${not empty courseSchedules[halfhourKey] ? courseSchedules[halfhourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                              <c:choose>
                                <c:when test="${not empty courseSchedules[halfhourKey]}">
                                  <a class="${courseSchedules[halfhourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[halfhourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[halfhourKey][0].courseRound.id}" style="color:#fff">
                                      ${courseSchedules[halfhourKey][0].student.name}
                                  </a>
                                </c:when>
                                <c:when test="${empty courseSchedules[halfhourKey] and empty restSchedules[halfhourKey]}">

                                </c:when>
                                <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and empty persist.containDuty(restSchedules[halfhourKey])}">
                                  值班
                                </c:when>
                                <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and not empty persist.containDuty(restSchedules[halfhourKey])}">
                                  ${persist.containDuty(restSchedules[halfhourKey]).coachRestType.description}
                                </c:when>
                              </c:choose>
                            </td>
                          </c:if>
                        </c:forEach>

                        <td>
                          <c:if test="${date >= today && (currentPrincipal.schedule || currentPrincipal.areaServer || currentPrincipal.siteServer)}">
                            <a href="${ctx.host}/schedules/calendar-edit?coach=${principal.key}&date=${day}&site=${coachRelations[principal.key].id}" class="init-button hide" data-toggle="modal" data-target="#schedule-edit">更改课时</a>
                            <a href="${ctx.host}/schedules/add-experience?coach=${principal.key}&date=${day}&site=${coachRelations[principal.key].id}" class="init-button hide" data-toggle="modal" data-target="#experience-add">体验</a>
                            <a href="${ctx.host}/schedules/cancel-experience?coach=${principal.key}&date=${day}&site=${coachRelations[principal.key].id}" class="init-button hide" data-toggle="modal" data-target="#experience-cancel">取消体验</a>
                          </c:if>
                        </td>
                      </tr>
                    </c:forEach>
                  </c:otherwise>
                </c:choose>
              </c:if>
            </c:forEach>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>

</div>

<%@ include file="/WEB-INF/include/footer.jsp"%>
<%@ include file="/WEB-INF/include/script.jsp"%>
<d:resource root="${ctx.resource}/build" type="script" src="js/page/course/schedule-index.js">
  <script type="text/javascript">
    var coachview = "${param.coachview}";
    var beginDate = "${param.beginDate}";
    var weekOffset = "${param.weekOffset}";
    var coachId = "${param.coachId}";
    require(['page/course/schedule-index'], function(page) {
      page.init({
        "coachview" : coachview,
        "beginDate" : beginDate,
        "weekOffset": weekOffset,
        "coachId" : coachId
      })
    })
  </script>
</d:resource>

</body>

</html>

